<?php
/**
 * @copyright meila.com
 * @author zhanglei11@
 * @name
 * @param
 *         $code = 加密串
 * @static
 *         点击激活邮件链接 进行激活操作
 *
 *
 */
include ('../../__global.php');
header("Content-type:text/html;charset=utf-8");
class active_register extends ml_controller
{
    private $code;

    public function initParam()    {
        $this->code = $this->input('code');
    }

    public function checkParam()
    {
        //检查权限
    }
    public function main()
    {
        $securecode = new ml_tool_securecode();
        $arrCode = $securecode->passport_decrypt($this->code);
        $email = $arrCode[0];
        $time = $arrCode[1];
          
        if(Tool_string::str_width($time)< 10){
            echo '<script type="text/javascript" language="javascript">alert("激活码错误，请重新激活");window.location.href="/page/self_index.php";</script>';die();
        //    $this->redirect('/page/self_index.php');
        }
        
        
        //根据解密出来的 email 获取用户信息
        $oAccount = new ml_model_dbUserAccount();
        $rs = $oAccount->getAccountByEmail($email);
        if(!$rs){
            echo '<script type="text/javascript" language="javascript">alert("激活失败，请重新激活");window.location.href="/page/self_index.php";</script>';die();
        //    $this->redirect('/page/self_index.php');
        }
        
        $row = $oAccount->get_data();
          
        if(empty($row['uid'])){
            echo '<script type="text/javascript" language="javascript">alert("激活失败，请重新激活");window.location.href="/page/self_index.php";</script>';die();
    //        $this->redirect('/page/self_index.php');
        }
        
        if ($row['status'] == ML_USERSTATUS_KILL) {
            echo '<script type="text/javascript" language="javascript">alert("该用户已被注销，请重新注册");window.location.href="/page/user/register.php";</script>';die();
        }
         
        
          
        //正常用户 已经激活 跳转到首页   首页会判断如果有登录就自动登录
        if($row['verify_email'] == ML_VERIFYED) {
            echo '<script type="text/javascript" language="javascript">alert("该用户已经激活");window.location.href="/page/self_index.php";</script>';die();
    //        $this->redirect('/page/self_index.php');
        }
        
        // 超过2天
        if(time() - $time >= 86400 * 2 ){
    //        $page = 'user::timeout';
    //        $this->page_output($page,$data);
            echo '<script type="text/javascript" language="javascript">alert("激活失败，请重新激活");window.location.href="/page/self_index.php";</script>';die();
    //        $this->redirect('/page/self_index.php');
        }
        
        // 改变数据库记录
        $oAccount->updateVerifyEmail(ML_VERIFYED,$row['uid']);
        ml_tool_sendMq::search_user('A', $row['uid']);
        
        $this->loginProxy(ml_login, $row);
        $this->loginProxy( modify_login, array('verify_email'=>ML_VERIFYED));
        
        
        if($this->__visitor['status']==2){
            echo '<script type="text/javascript" language="javascript">alert("激活成功");window.location.href="/page/self_index.php";</script>';
        }
        else{
            echo '<script type="text/javascript" language="javascript">alert("激活成功");window.location.href="/page/relation/recommend.php";</script>';
        }
        // $page = 'user::complete_infor';

        $this->set_scope_var('$notice',"");


        $data['title'] = '登录注册-引导填写';
        //        $this->page_output( $page, $data);
    }

}
new active_register();